package com.zhanghu.backendZray.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhanghu.backendZray.mapper.OilPriceMapper;
import com.zhanghu.backendZray.pojo.entity.OilPrice;
import com.zhanghu.backendZray.pojo.vo.oilPrice.OilPriceVo;
import com.zhanghu.backendZray.service.OilPriceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 油价 服务实现类
 * </p>
 *
 * @author zhangdong
 * @since 2025-01-19
 */
@Service
@Slf4j
public class OilPriceServiceImpl extends ServiceImpl<OilPriceMapper, OilPrice> implements OilPriceService {

    /**
     * 查询今日油价
     */
    @Override
    public List<OilPriceVo> today() {
        LambdaQueryWrapper<OilPrice> wrapper = new LambdaQueryWrapper<>(OilPrice.class).eq(OilPrice::getPullDate, LocalDate.now());
        List<OilPrice> list = list(wrapper);
        return list.stream().map(r -> {
            OilPriceVo oilPriceVo = new OilPriceVo();
            BeanUtil.copyProperties(r, oilPriceVo);
            return oilPriceVo;
        }).collect(Collectors.toList());
    }
}
